﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace WSBackup
{
    class RevisionHeader
    {
        public RevisionHeader(UInt64 buff)
            : this((UInt32)(buff >> 32), (UInt32)buff)
        {

        }

        public RevisionHeader(UInt32 Size, UInt32 FileTime)
        {
            this._size = Size;
            this._fileTime = FileTime;
        }

        public RevisionHeader(UInt32 Size, DateTime DateTime)
        {
            this.Size = Size;
            this.DateTime = DateTime;
        }

        public DateTime DateTime
        {
            // Pocet sekund of 1.1.2000
            get { return new DateTime((Int64)(63082281600 + _fileTime) * 10000000); }
            set { _fileTime = (value.Ticks < 630822816000000000) ? 0 : (UInt32)((value.Ticks - 630822816000000000) / 10000000); }
        }

        public UInt32 Size
        {
            get { return _size; }
            set { _size = value; }
        }

        //public Int64 Value
        //{
        //    get { return ((Int64)_size << 32) | _fileTime; }
        //}

        public void AppendHeader(Stream stream)
        {
            Int64 value = _fileTime + ((Int64)_size << 32);
            stream.Seek(0, SeekOrigin.End);
            stream.Write(BitConverter.GetBytes(value), 0, 8);
        }

        private UInt32 _size;
        private UInt32 _fileTime; // Pocet sekund of 1.1.2000
    }
}
